import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/*
 * 适配Android状态栏背景和状态栏字体颜色
 */
class StateBarFulWidget extends StatefulWidget {
  final bool stateBarTextColor; //状态栏字体颜色
  final Color systemNavigationBarColor; //状态栏底部按键背景颜色
  final Color backgroundColor; //背景颜色
  final Widget child; //子控件
  final PreferredSizeWidget appBar; //AppBar,Scaffold自带参数
  final Widget floatingActionButton; //右下键Button，Scaffold自带参数
  final Key key;

  StateBarFulWidget({this.key,
    this.stateBarTextColor = true,
    this.backgroundColor = Colors.white,
    this.systemNavigationBarColor = Colors.transparent,
    @required this.child,
    this.appBar,
    this.floatingActionButton});

  @override
  State<StatefulWidget> createState() => StateBarStateFulWidget();
}

class StateBarStateFulWidget extends State<StateBarFulWidget> {
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      key: widget.key,
      child: Scaffold(
        backgroundColor:widget.backgroundColor,
        appBar: widget.appBar,
        body: widget.child,
        floatingActionButton: widget.floatingActionButton,
      ),
      value: (widget.stateBarTextColor
          ? SystemUiOverlayStyle.light
          : SystemUiOverlayStyle.dark)
          .copyWith(systemNavigationBarColor: widget.systemNavigationBarColor)
          .copyWith(statusBarColor: widget.systemNavigationBarColor),
    );
  }
}
